# Copyright (c) 2007 Chris Moyer http://coredumped.org
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from ds import DataSource

class Compute(DataSource):
	"""
	Compute is for storing the result of a formula applied to other 
	data sources in the RRD. This data source is not supplied a value
	on update, but rather its Primary Data Points (PDPs) are computed
	from the PDPs of the data sources according to the rpn-expression
	that defines the formula. Consolidation functions are then applied 
	normally to the PDPs of the COMPUTE data source (that is the 
	rpn-expression is only applied to generate PDPs). In database 
	software, such data sets are referred to as ``virtual'' or 
	``computed'' columns.

	rpn-expression defines the formula used to compute the PDPs of 
	a COMPUTE data source from other data sources in the same <RRD>. 
	It is similar to defining a CDEF argument for the graph command.
	Please refer to that manual page for a list and description of 
	RPN operations supported. For COMPUTE data sources, the following 
	RPN operations are not supported: COUNT, PREV, TIME, and LTIME. 
	In addition, in defining the RPN expression, the COMPUTE data 
	source may only refer to the names of data source listed previously 
	in the create command. This is similar to the restriction that 
	CDEFs must refer only to DEFs and CDEFs previously defined in the 
	same graph command.

	Name: The name of this DS
	rpn_expression: This is the expression for this system.
	"""
	def __init__(self, name, rpn_expression):
		self.name = name
		self.type = "COMPUTE"
		self.arguments=rpn_expression
